package com.google.appengine.api.datastore;

import com.googlecode.objectify.generic.DatastoreServiceAdaptor;
import com.googlecode.objectify.generic.IdRangeAllocator;
import com.googlecode.objectify.hbase.HBaseAsyncDatastoreService;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Secondary User
 */
public class DatastoreServiceFactory
{

	public static AsyncDatastoreService getAsyncDatastoreService(DatastoreServiceConfig config)
	{
		if (config.getType() == DatastoreServiceConfig.Type.HBASE)
		{
			try
			{
				return new HBaseAsyncDatastoreService(config);
			}
			catch (Exception ex)
			{
				throw new RuntimeException(ex);
			}
		}
		//TODO: Add non-HBase versions here.
		return null;
	}

	public static DatastoreService getDatastoreService()
	{
		return getDatastoreService(DatastoreServiceConfig.Builder.withDefaults());
	}

	public static AsyncDatastoreService getAsyncDatastoreService()
	{
		return getAsyncDatastoreService(DatastoreServiceConfig.Builder.withDefaults());
	}

	public static DatastoreService getDatastoreService(DatastoreServiceConfig config)
	{
		AsyncDatastoreService async = getAsyncDatastoreService(config);
		if (async instanceof IdRangeAllocator)
		{
			return new DatastoreServiceAdaptor(async, (IdRangeAllocator) async);
		}
		return null;
	}
}
